#include "./tim_vector.h"
#include "./tim_list.h"
#include "./tim_circlelist.h"
#ifndef TIM_STACK_TIM_QUEUE_H
#define TIM_STACK_TIM_QUEUE_H

namespace tim
{
	template<typename T>
	class stack: public tim::list<T>
	{
		public:
			void push(T const& e) { this->insert_back(e); };//入栈
			T pop() { return this->remove_back(); }//出栈
			T& top() { return this->last()->data; }//取栈首
			bool empty() {return this->size() == 0;};//判空
	};

	template<typename T>
	class queue: public tim::list<T>
	{
		public:
			void enqueue(T const& e) { this->insert_back(e);}//入队
			T dequeue() { return this->remove_front(); }//出队
			T& front() {return this->first()->data;};//取队首
			T& back() {return this->last()->data;}//取队尾
			bool empty() {return this->size() == 0;};//判空
	};

	template<typename T>
	class stack2: public tim::vector<T>
	{
		public:
			void push(T const& e) { this->insert(0, e); };//入栈
			T pop() { return this->remove(0); }//出栈
			T& top() { return this->operator[](0); }//取栈首
			bool empty() {return this->is_empty();};//判空
	};

	template<typename T>
	class queue2: public tim::vector<T>
	{
		public:
			void enqueue(T const& e) { this->insert(this->size(), e);}//入队
			T dequeue() { return this->remove(0); }//出队
			T& front() {return this->operator[](0);};//取队首
			T& back() {return this->operator[](this->size() - 1);};//取队尾
			bool empty() {return this->is_empty();};//判空
	};

	template<typename T>
	class circle_queue: public tim::circlelist<T>
	{
		private:
			node<T>* cur;

		public:
			circle_queue(): circlelist<T>(), cur(this->cur) { cur = this->trailer; };
			void next() { cur = cur->pred; };
			void enqueue(T const& e)
			{
				node<T>* new_node = new node<T>(e, cur->pred, cur);
				cur->pred->succ = new_node;
				cur->pred = new_node;
				this->_size++;
				next();
			};
			T dequeue()
			{
				node<T>* temp = cur;
				for (; temp->succ != this->trailer; temp = temp->succ);
				return this->remove_back();
			}
			bool empty() { return this->size() == 0;};
	};
}

#endif